<?php
/**
 * @Author: Shauan Andrade {shauanandrade@gmail.com}.
 * @DateTime: 14/02/15 - 21:25
 */

namespace system\Controller;

class UsuariosController extends SystemAppController {

    public function indexAction($page=1){
        $usuarios = $this->Pagination($page,['viewLinks'=>4]);
        $this->set(compact('usuarios'));
        $this->render('index');
    }

    public function createAction(){
        if($this->request->is('post')) {
            if($this->Usuarios->isValidate($this->request->post())) {
                $post = $this->request->post();
                $post['status'] = $post['status'] == 1 ? 1 : 0;
                if($this->Usuarios->saveData($post)) {
                    $this->Session->setFlash('Registro salvo com sucesso.');
                    $this->redirect(['action'=>'index']);
                }else {
                    $this->Session->setFlash('Houve um erro ao salvar o registro.',['type'=>'danger']);
                    $this->redirect(['action'=>'index']);
                }
            }
        }
        $this->render();
    }
}